import { get, post } from "../utils/http";
import { JEECG_BOOT, BASE_URL } from "../utils/base_url";

/**
 * 登录
 * @param {Object} data
 * @returns {Promise}
 * 
*/
export const login = (data) => post(`/${JEECG_BOOT}/user/clubUser/mLogin`, data, false);

/**
 * 获取用户信息
 * @returns {Promise}
 */
export const getUserInfo = () => get(`/${JEECG_BOOT}/user/clubUser/queryByOpenId`, {}, true);

/** 
 * 修改用户信息
 */
export const editUserInfo = (data) => post(`/${JEECG_BOOT}/user/clubUser/edit`, data, true);

/**
 * 上传文件
 */
export const uploadFile = (data) => {
  console.log(data, 'data');
  return new Promise((resolve, reject) => {
    wx.uploadFile({
      url: `${BASE_URL}/${JEECG_BOOT}/upload/upload`,
      filePath: data.file,
      header: {
        'X-Access-Token': wx.getStorageSync('openId'),
      },
      name: 'file',
      success: (res) => {
        const data = JSON.parse(res.data || '{}');
        console.log(data, 'uploadFile');
        if (data.code == 200) {
          resolve(data.result);
        } else if (data.code == 401) {
          wx.showToast({
            title: data.message,
            icon: "none",
          });
          wx.clearStorageSync('openId');
          wx.navigateTo({
            url: '/pages/index/index',
          });
          reject(data);
        }
      },
      fail: (res) => {
        
        wx.showToast({
          title: res.message,
          icon: "none",
        });
        reject(res);
      }
    });
  });
}

/**
 * 获取订单列表
 * @param {Object} data
 * @returns {Promise}
 */
export const getOrderList = (data) => get(`/${JEECG_BOOT}/order/clubOrder/list`, data, true);

/**
 * 获取订单详情
 */
export const getOrderDetail = (data) => get(`/${JEECG_BOOT}/order/clubOrder/queryById`, data, true);


/**
 * 获取轮播图
 */
export const getLunBo = () => get(`/${JEECG_BOOT}/lunbo/lunBo/listAll`, {}, false);

/** 
 * 获取消息列表
 */
export const getMessageList = () => get(`/${JEECG_BOOT}/msg/message/listAll`, {}, false);

/** 
 * 获取地址列表
 */
export const getAddrList = () => get(`/${JEECG_BOOT}/addr/userAddr/listAllByUser`, {}, true);

/**
 * 添加地址
 */
export const addAddr = (data) => post(`/${JEECG_BOOT}/addr/userAddr/add`, data, true);

/**
 * 修改地址
 */
export const editAddr = (data) => post(`/${JEECG_BOOT}/addr/userAddr/edit`, data, true);

/**
 * 获取地址详情
 */
export const getAddrDetail = (data) => get(`/${JEECG_BOOT}/addr/userAddr/queryById`, data, true);

/**
 * 删除地址
 */
export const deleteAddr = (data) => post(`/${JEECG_BOOT}/addr/userAddr/delete`, data, true);


/**
 *   - 可选小区范围
 */
export const getTaskConfig = () => get(`/${JEECG_BOOT}/config/taskConfig/listRange`, {}, true);


/**
 * 添加接单员
 */
export const addReceiver = (data) => post(`/${JEECG_BOOT}/receiver/receiver/add`, data, true);

/**
 * 获取接单员信息
 */
export const getReceiverInfo = (data) => get(`/${JEECG_BOOT}/receiver/receiver/queryByOpenId`, data, true);


/**
 * 获取用户优惠券列表
 */
export const getUserGiftList = (data) => get(`/${JEECG_BOOT}/usergift/userGift/list`, data, true);


/**
 * 添加订单
 */
export const addOrder = (data) => post(`/${JEECG_BOOT}/order/clubOrder/add`, data, true);

/**
 * 修改订单
 */
export const editOrder = (data) => post(`/${JEECG_BOOT}/order/clubOrder/edit`, data, true);

/**
 * 支付订单
 */
export const payOrder = (data) => post(`/${JEECG_BOOT}/order/clubOrder/pay`, data, true);

/**
 * 获取邀请码
 */
export const getInviteCode = () => get(`/${JEECG_BOOT}/user/clubUser/getInviteCode`, {}, true);


/**
 * 获取手续费率
 */
export const getFeeRate = () => get(`/${JEECG_BOOT}/config/taskConfig/getFeeRate`, {}, true);

/**
 * 获取接单员余额
 */
export const getReceiverBalance = () => get(`/${JEECG_BOOT}/receiver/receiver/queryBalance`, {}, true);


/**
 * 获取接单员分析
 */
export const getReceiverAnalyse = () => post(`/${JEECG_BOOT}/receiver/receiver/analyse`, {}, true);


/**
 *  签到
 */
export const getuserSign = () => post(`/${JEECG_BOOT}/sign/userSign/add `, {}, true);

/**
 *    - 积分换券
 */
export const scoreRecord = (cardId) => post(`/${JEECG_BOOT}/score/scoreRecord/exchange/?cardId=${cardId}`, {}, true);

/**
 * 获取签到信息
 */
export const getSignInfo = () => get(`/${JEECG_BOOT}/sign/userSign/queryByOpenId`, {}, true);



